<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" id="html">
    <head>
        <title></title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <base href="<?= base_url(1); ?>" />
        <script type="text/javascript" src="<?= $config['res_url'] ?>/js/jquery.min.js?ver=<?= $config['version'] ?>"></script>
        <link type="text/css" href="css/main.css?v=<?= $config['version'] ?>" rel="stylesheet" />
        
	<script type="text/javascript" language='javascript'>

	//有参数调用
    $(document).ready(function() {

    	//ajax回调
    	$('#rolename').blur(function (){
	    	var area = $("#area").val();
	 		var rol = $("#rolename").val();
	 		var ur = "<?= site_url("general/getRoleId") ?>";
	 		
	    	$.ajax({
		    		type: "post",
		
		    		url: ur,
					data:'areanum='+area+'&rolename='+rol,
					
		    		beforeSend: function(XMLHttpRequest){
		    			 $("#showText").text("before send");
		    			 $("#showText").css("background","#f00");
		    			//ShowLoading();
		    		},
		    		
		    		success: function(data, textStatus){
						//alert('success');
						$("#showText").text(textStatus);
						//alert('('+data+')');
						var d = eval('('+data+')');
						//alert('data='+data+' status='+textStatus);		
						//alert('accountid='+data.accountid);
						//alert(d);
						//alert(d.accountid);
						if(-1 != d.roleid)	//找到玩家了
						{
							$("#role_id").val(d.roleid)
							$("#showText").text(' get  role_id '+textStatus)
							$("#showText").css("background","#fff");
						}else
						{
							$("#showText").text('rolename error,plz input again');
							$("#showText").css("background","#f00");
						}
		    		},	
		    			
		    		complete: function(XMLHttpRequest, textStatus){
						//alert('status');
		    			//HideLoading();
		    			//$("#showText").text(textStatus);
		    		},
		    		
		    		error: function(){
						//alert('connect server error');
		    			$("#showText").text('connect server error');
		    			$("#showText").css("background","#f00");
		    		}
		    		
	    		});
    	});
    	

        //检验role_id是否正确
        $("#submit").click(function() {
        	var account = $("#role_id").val();
        	//alert('account:'+account);
        	if(-1 == account)
        	{
        		$("#showText").text('role name error,plz input error');
        		alert('role name error,plz input error');
            	return false;
        	}
        });
    });  

	</script>
	
    </head>
    <body>
        <?php include(VIEWPATH . 'common/main_header.php'); ?>
        <?php 
        	//var_dump($areaList); 
        	//print_r($areaList);
        ?>
        <form action="" method="POST" id="rowForm">
            <table width="100%" border="0" cellspacing="1" cellpadding="0" class="tablegrid tableedit">
            <tr><td><?= translate('SEAL_SELECT_PLATFORM') ?>:</td><td><?= $platformlist?></td></tr>
                <tr><td><?= translate('SELECT_AREA') ?>:</td><td>
                  <select name="row[area]" id="area">
                  	<?php foreach ($areaList as $key=>$value) { ?>
                    <option value="<?=$key ?>"><?=$value["name"] ?></option>
                    <?php } ?>
                  </select>
                  </td></tr>
                <tr><td><?= translate('ROLE_NAME') ?>:</td>
                	<td><input type="text" name="row[role_name]" id="rolename" size="25" /></td>  
                </tr>
                <tr><td><?= translate('STATE') ?>:</td>
                	<td><p id="showText" style="background:#FF0000">unknow rolename</p></td>
                </tr>
                
                <tr><td><?= translate('SEAL_TIME') ?>:</td><td><?= $timelist?></td></tr>
				<tr><td><?= translate('SEAL_DES') ?>:</td><td>
                    <textarea cols="50" rows="5" name="row[description]" id="description"></textarea></td></tr>
                <tr><td></td><td>
                <input type="submit" value="<?= translate('SUBMIT') ?>" id="submit" /> 
                </td></tr>
            </table>
            
            <input type="hidden" name="row[role_id]" id="role_id" value="-1"/>
        </form>
        <script type="text/javascript">
            SG.init("core.form", function() {
                $.formValidator.initConfig({formid: "#rowForm", submitonce: true});
                $("#area_host").formValidator({empty: false, onshow: '<?= translate('PLASE_SELECT') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#rolename").formValidator({empty: false, onshow: '<?= translate('PLASE_INPUT_ROLE_NAME') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#description").formValidator({empty: false, onshow: '<?= translate('PLASE_INPUT_DES') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});   
                $("#sealtime").formValidator({empty: false, onshow: '<?= translate('AREA_FORM_INPUT_OPENTIME') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
            });

        </script>
    </body>
</html>
